<template>
  <div class="main">
    <div class="search">
      <div class="block">
        标签名称：
        <el-input
          placeholder="请输入标签名称"
          prefix-icon="el-icon-search"
          v-model="signName"
          style="width:200px">
        </el-input>
      </div>
      <div class="block">
        标签ID：
        <el-input
          placeholder="请输入标题"
          prefix-icon="el-icon-search"
          v-model="titleName"
          style="width:200px">
        </el-input>
      </div>
      <div class="block">
        <el-button type="primary" style="width:80px;" @click="search()" size="small">查询</el-button>
      </div>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="ID" label="ID" sortable width="240" align="center"></el-table-column>
      <el-table-column prop="sign" label="标签" width="320" align="center"></el-table-column>
      <el-table-column prop="number" label="文章数" width="320" align="center"></el-table-column>
      <el-table-column prop="createdTime" sortable label="创建时间" width="360" align="center"></el-table-column>
      <el-table-column fixed="right" label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="primary" size="small">查看文章</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 模态框 -->
    <div class="shadow-model" v-if="addShow" @click="closeAdd()">
      <div class="el-icon-circle-close close" @click="closeAdd()"></div>
      <div class="add-w" @click="(e)=>{e.stopPropagation()}">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="活动名称">
            <el-input v-model="form.name" style="width:200px;"></el-input>
          </el-form-item>
          <el-form-item label="活动地址">
            <el-select v-model="form.address" placeholder="请选择活动地址" style="width:200px;">
              <el-option label="地址一" value="shanghai"></el-option>
              <el-option label="地址二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="活动时间">
            <el-date-picker type="date" placeholder="选择日期" v-model="form.date" style="width:200px;"></el-date-picker>
          </el-form-item>
          <el-form-item label="即时配送">
            <el-switch v-model="form.delivery"></el-switch>
          </el-form-item>
          <el-form-item label="活动性质">
            <el-checkbox-group v-model="form.type" @change="changeType">
              <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
              <el-checkbox label="地推活动" name="type"></el-checkbox>
              <el-checkbox label="线下主题活动" name="type"></el-checkbox>
              <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="特殊资源">
            <el-radio-group v-model="form.resource">
              <el-radio label="线上品牌商赞助"></el-radio>
              <el-radio label="线下场地免费"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">立即创建</el-button>
            <el-button @click="addShow = false">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <div class="shadow-model" v-if="editShow" @click="closeEdit()">
      <div class="el-icon-circle-close close" @click="closeEdit()"></div>
      <div class="add-w" @click="(e)=>{e.stopPropagation()}">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="活动名称">
            <el-input v-model="editForm.name" style="width:200px;"></el-input>
          </el-form-item>
          <el-form-item label="活动地址">
            <el-select v-model="editForm.address" placeholder="请选择活动地址" style="width:200px;">
              <el-option label="地址一" value="shanghai"></el-option>
              <el-option label="地址二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="活动时间">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="editForm.date"
              style="width:200px;"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="即时配送">
            <el-switch v-model="editForm.delivery"></el-switch>
          </el-form-item>
          <el-form-item label="活动性质">
            <el-checkbox-group v-model="editForm.type" @change="changeType">
              <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
              <el-checkbox label="地推活动" name="type"></el-checkbox>
              <el-checkbox label="线下主题活动" name="type"></el-checkbox>
              <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="特殊资源">
            <el-radio-group v-model="editForm.resource">
              <el-radio label="线上品牌商赞助"></el-radio>
              <el-radio label="线下场地免费"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="save(editForm)">保存</el-button>
            <el-button @click="editShow = false">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "home",
  data() {
    return {
      tableData: [
        {
          ID:1961,
          sign: '疫情',
          number: 1,
          createdTime: '2020-08-17 15:19:08',
        },
        {
          ID:1960,
          sign: '赚钱',
          number: 1,
          createdTime: '2020-05-10 17:21:25',
        }
      ],
      addShow: false,
      form: {
        name: "",
        address: "",
        date: "",
        delivery: 0,
        type: [],
        resource: "",
      },
      editShow: false,
      editForm: {},
      signName:'',
      titleName:''
    };
  },
  methods: {
    add() {
      this.addShow = true;
    },
    closeAdd() {
      this.addShow = false;
    },
    edit(row) {
      this.editForm = row;
      this.editShow = true;
    },
    closeEdit() {
      this.editShow = false;
    },
    onSubmit() {
      this.form.date = this.$moment(this.form.date).format("YYYY-MM-DD");
      this.tableData.push(this.form);
      this.closeAdd();
    },
    save(editForm) {
      this.form.date = this.$moment(this.form.date).format("YYYY-MM-DD");
      console.log(editForm.name);
      this.closeEdit();
    },
    handleClick(row) {
      console.log(row);
    },
    changeType(value) {
      console.log(value);
    },
  },
  mounted() {
    console.log("生命周期mounted");
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
@import "../../css/home.scss";
</style>
